#ifndef FFGLBMD_H
#define FFGLBMD_H

#include <FFGLShader.h>
#include "../FFGLPluginSDK.h"

#include <FFGL.h>
#include <FFGLExtensions.h>
#include <FFGLLib.h>

#include <stdio.h>

#include "../../../../../../Blackmagic DeckLink SDK 9.7.1/Mac/include/DeckLinkAPI.h"
#include "cameradecklink.h"

class FFGLBMD :
public CFreeFrameGLPlugin
{
public:
	FFGLBMD();
  virtual ~FFGLBMD();

	///////////////////////////////////////////////////
	// FreeFrame plugin methods
	///////////////////////////////////////////////////

	DWORD	SetParameter(const SetParameterStruct* pParam);
	DWORD	GetParameter(DWORD dwIndex);
	char*   GetParameterDisplay(DWORD dwIndex);

	DWORD	ProcessOpenGL(ProcessOpenGLStruct* pGL);
	DWORD	SetTime(double time);

	DWORD InitGL(const FFGLViewportStruct *vp);
	DWORD DeInitGL();

	///////////////////////////////////////////////////
	// Factory method
	///////////////////////////////////////////////////

	static DWORD __stdcall CreateInstance(CFreeFrameGLPlugin **ppInstance)
	{
		*ppInstance = new FFGLBMD();
		if (*ppInstance != NULL) return FF_SUCCESS;
		return FF_FAIL;
	}

protected:
	// Time
	double m_curTime;
	
	// Parameters
	int m_CameraIndex;
	int m_VideoModeIndex;
	
	int pickDevice(int cameraIndex);
	
	IDeckLink*          m_DeckLink;
	IDeckLink*          m_SelectedDecklinkDevice;
	CameraDecklink*     m_Camera1;

	void bail();

	FFGLExtensions m_extensions;
	FFGLShader m_shader;
	
	GLint m_inputTextureLocation;
	GLint m_dimensionsLocation;
	char* vertexShaderCode;
	char* fragmentShaderCode;
	
	GLuint m_bmdTextureId;
	
	GLint m_InW;
	GLint m_InH;
	
	bool m_Init;
	void* frameBytes;
};


#endif

